package com.template.filter;

import com.template.common.constant.ApiGroup;
import com.template.common.constant.ApiType;
import com.template.common.constant.ConstantPool;
import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter;

import java.io.IOException;

/**
 * @author mltong
 */
@Component
public class AuthFilter extends OncePerRequestFilter {

    @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws ServletException, IOException {
        String servletPath = request.getServletPath();
        if (servletPath.contains(ApiType.DOC)) {
            chain.doFilter(request, response);
        }else{
            String token = request.getHeader(ConstantPool.HEADER_TOKEN);
//            String accessToken = tenantService.checkAccessToken(token);
//            if(StringUtils.isEmpty(token) || StringUtils.isEmpty(accessToken)){
//                response.setStatus(HttpStatus.HTTP_UNAUTHORIZED);
//                return;
//            }
            chain.doFilter(request, response);
        }
    }
}
